from Page.Page2 import Page2
from selenium.webdriver.common.by import By

class Page3(Page2):
    shou_loc = (By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a')
    def shou(self):
        self.click(self.shou_loc)

    search_loc = (By.XPATH,'//input[@class="search-input" or @name="keywords"]')
    def search(self):
        self.send_keys(self.search_loc,'非洲之心')

    searchbtn_loc = (By.XPATH,'//*[@id="searchForm"]/div[2]/input')
    def searchbtn(self):
        self.click(self.searchbtn_loc)

    shopping_loc = (By.XPATH,'//img[@src="/uploads/images/20250606/af9ef24936d60ea1dfe55120bccc1906.png"]')
    def shopping(self):
        self.Webdriverwait(self.shopping_loc)

    buy_loc = (By.XPATH,'//a[@id="buy-cart" and @class="shop-btn"]')
    def buy(self):
        self.click(self.buy_loc)

    address_loc = (By.ID,'address-828')
    def address(self):
        self.click(self.address_loc)

    next_loc = (By.ID, 'order-button')
    def next(self):
        self.click(self.next_loc)

    dy3_loc = (By.XPATH, '/html/body/div[4]/div[4]/div[2]/ul/li[1]')
    def dy3(self):
        dy3 = self.text(self.dy3_loc)
        print(dy3)

    look_loc = (By.XPATH,'/html/body/div[4]/div[3]/p/a')
    def look(self):
        self.click(self.look_loc)

    dy4_loc = (By.XPATH,'/html/body/div[5]/div[2]/div/div[2]/table[2]/tbody/tr[2]/td[2]')
    def dy4(self):
        dy4 = self.text(self.dy4_loc)
        print(dy4)

    def luoji_A3mall_shopping(self):
        try:
            self.luoji_A3mall_login()
            self.sleep(2)
            self.shou()
            self.search()
            self.searchbtn()
            self.shopping()
            self.buy()
            self.sleep(2)
            self.address()
            self.next()
            self.sleep(2)
            self.dy3()
            self.look()
            self.dy4()
        except Exception as e:
            print(e)
            self.screenshot()